package com.ysxsoft.wdg.ui.activity.my.partner;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.classic.common.MultipleStatusView;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.response.MyBagResponse;
import com.ysxsoft.wdg.bean.response.QuestionDetailResponse;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.net.UrlHost;
import com.ysxsoft.wdg.util.JsonUtils;
import com.ysxsoft.wdg.util.ToastUtils;
import com.ysxsoft.wdg.util.WebViewUtils;
import com.ysxsoft.wdg.util.sp.SharePrefUtils;
import com.ysxsoft.wdg.util.statusbar.StatusBarUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;

public class CommonQustDetailActivity extends BaseActivity {


    public static void start(Context context, String detail_id) {
        Intent intent = new Intent(context, CommonQustDetailActivity.class);
        intent.putExtra("detail_id", detail_id);
        context.startActivity(intent);
    }

    @BindView(R.id.topView)
    View topView;  @BindView(R.id.multStatusView)
    MultipleStatusView multStatusView;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.webView)
    WebView webView;
    private String qid;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_common_qust_detail;
    }

    @Override
    protected void initData() {
        StatusBarUtil.setStatusBarTextColor(this, true);
        initStatusBar(topView, true);
        titleContent.setText("常见问题");
        qid = getIntent().getStringExtra("detail_id");
        WebViewUtils.init(webView);
        getData();
    }

    /**
     * 获取答案
     */
    private void getData() {
        multStatusView.showLoading();
        OkHttpUtils.post()
                .url(UrlHost.QUESTION_DETAIL)
                .addParams("qid", qid)
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                if (!call.isCanceled()) {
                    multStatusView.showContent();
                }
            }

            @Override
            public void onResponse(String response, int id) {
                multStatusView.showContent();
                if (response != null) {
                    QuestionDetailResponse questionDetailResponse = JsonUtils.parseByGson(response, QuestionDetailResponse.class);
                    if (questionDetailResponse == null) {
                        return;
                    }
                    if (CallbackCode.SUCCESS.equals(questionDetailResponse.getCode())) {
                        String da = questionDetailResponse.getData();
                        WebViewUtils.setData(webView, da);
                    } else {
                        ToastUtils.showToast(questionDetailResponse.getMs());
                    }
                } else {
                }
            }
        });
    }

    @Override
    protected void setListener() {
    }

    @OnClick(R.id.title_finish)
    public void onViewClicked() {
        finish();
    }
}
